package com.jysz.certificate.web.action.mytask;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.jysz.certificate.action.AbstractBaseAction;
import com.jysz.certificate.persistence.enums.PostType;
import com.jysz.certificate.persistence.model.mytask.Prewarning;
import com.jysz.certificate.persistence.model.pm.PerformanceAssign;
import com.jysz.certificate.service.cm.CertificationService;
import com.jysz.certificate.service.pm.PerformanceAssignShopDetailService;
import com.jysz.certificate.service.pm.PmUserService;
import com.jysz.certificate.service.system.TreatyService;
import com.jysz.certificate.utils.JsonUtil;

@Controller
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@Namespace("/mytask")
public class PromotAction  extends AbstractBaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Resource
	private CertificationService certificationService;//合格证
	@Resource
	private TreatyService treatyService;//协议
	@Resource
	private PmUserService pmUserService;//绩效人员名单确认
	@Resource
	private PerformanceAssignShopDetailService performanceAssignShopDetailService;//绩效确认
	
	private Prewarning prewarning;//预警提示
	private List<Prewarning> prewarnings;//
	
	/**
	 * 汇款预警，到店预警
	 */
	public void scheduledBenin(){
		prewarnings.addAll(certificationService.prewarningList(true,0));//到店预警
		prewarnings.addAll(certificationService.prewarningList());//到店预警
		prewarnings.addAll(certificationService.prewarningList(true,1));//汇款预警
		prewarnings.addAll(certificationService.prewarningList(false,1));//汇款预警
	}
	/**
	 * 协议到期
	 */
	public void treatyBenin(){
		prewarnings.addAll(treatyService.prewarnings(true));
		prewarnings.addAll(treatyService.prewarnings(false));
	}
	/**
	 *绩效人员名单确认 
	 */
	public void puUserList(){
		prewarnings.addAll(pmUserService.remindPmUser(getUser()));
	}
	/**
	 * 绩效确认--区域经理
	 */
	public void affirm(){
		prewarnings.addAll(performanceAssignShopDetailService.prewarningList(getUser()));
	}
	
	@Action("prew")
	public String prew(){
		prewarnings = new ArrayList<Prewarning>();
		scheduledBenin();//------汇票 到店
		treatyBenin();//--------协议
		if(getUser().getPost().equals(PostType.Manager)){
			puUserList();//-------绩效人员名单
			affirm();//-----------绩效确认
		}
			
		Gson gson = new Gson();
		this.setJsonText(gson.toJson(prewarnings));
		return JSON_PAGE;
	}
	public Prewarning getPrewarning() {
		return prewarning;
	}
	public void setPrewarning(Prewarning prewarning) {
		this.prewarning = prewarning;
	}
	public List<Prewarning> getPrewarnings() {
		return prewarnings;
	}
	public void setPrewarnings(List<Prewarning> prewarnings) {
		this.prewarnings = prewarnings;
	}
	
	

}
